<?include_once('conn.php');?>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<? include_once('inc_head.php'); ?>
</head>

<?$act=$_GET['act'];
$tablename=TABLE_C.'admin';
switch($act){
	///////////////////////////////修改密码/////////////////////////////////////////////////////////////
	case 'editok':
	$id=$_POST['id'];
	$pass=$_POST['text_pass'];
	$pass=md5($pass);
	$cmd="update $tablename set pass='".$pass."' where id=".$id;
	echo $cmd;
	if(mysql_query($cmd))	{		
	gourl("修改密码成功",$cururl);
	}else{		echo mysql_error();	}
	exit;
	//////////////////////////////删除/////////////////////////////////////////////////////////////
	case 'del':	
	$id=$_GET['id'];
	$cmd="delete  from $tablename where id=".$id;
	if(mysql_query($cmd))	{		
	gourl("删除管理员成功",$cururl);
	}else{		echo mysql_error();	}
	exit;
	////////////////////////////添加/////////////////////////////////////////////////////////////
	case 'add';
	$name=$_POST['text_name'];
	$pass=$_POST['text_pass'];
	$pass=md5($pass);
		if(mysql_num_rows(mysql_query("select * from $tablename where name='$name'"))>0){
			gourl("用户名已存在",$cururl);
			exit;
		}
	$cmd="insert into $tablename(name,pass)values('".$name."','".$pass."')";
	if(mysql_query($cmd))	{	
	gourl("添加管理员成功",$cururl);
	}else{		echo mysql_error();	}
	exit;
}
?>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
</head>
<body >
	<?local('管理员设置');?>
<div id="intro"> 

<?
//////////////////////////////////////////默认显示列表/////////////////////////////////////////
if($act==''){
$page=$_GET['page'];
$sqltxt="select * from $tablename order by id";
$data1=$mydb->fetchbypage($sqltxt,120,$page);
?>
<div>
	<a href="?act=addadmin" class="btn btn-primary" rel="floatEdit">添加管理员</a> 
	<a href="?act=cmpass" class="btn btn-primary" rel="floatEdit">修改我的密码</a>
	<a href="admin_manager_power.php" class="btn btn-warning" rel="floatEdit">权限列表</a>
</div>

  <!-- ///////////////////////////// 列表 ///////////////////////////////// -->
  <br>
<table class="table table-hover table-bordered table-striped" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="">
  <tr> 
    <th width="" class="">管理名称</th>
    <th width="" height="30" class="">密码 </th>
    <th width="" class="">操作</th>
  </tr>

<?
for($i=0;$i<count($data1['data']);$i++){
	echo " <tr class=''> ";
	echo "   <td align='center' >{$data1['data'][$i]['name']}</td>";
	echo "   <td align='center'>{$data1['data'][$i]['pass']}</td>";
	echo "  <td align='center'>";
	echo "  <a href=admin_manager_edit.php?id={$data1['data'][$i]['id']}  rel=\"floatEdit\" class='btn btn-info btn-xs'>修改</a>";
	echo "  <a href='javascript:del({$data1['data'][$i]['id']})' class='btn btn-danger btn-xs'>删除</a>";
	echo "  </td>";
echo " </tr>";
}
  
?>
</table>
 <?}?>
<? //////////////////////////////////////////添加管理员/////////////////////////////////////////
if ($act=='addadmin'){?>
	<div class="local2"><b>添加管理员</b></div>
	<form name="form1" method="post" action="?act=add">
          <table class="table_form" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="">
            <tr> 
              <td width="100">管理名称</td>
              <td width="" ><input name="text_name" type="text"  value="" class=":required :min_length  form-control input-md">              </td>
            </tr>
            <tr> 
              <td>管理密码</td>
              <td ><input name="text_pass" type="text"  value="" class=" form-control input-md">              </td>
            </tr>
             <tr> 
              <td>&nbsp;</td>
              <td ><button type="submit" class="btn btn-primary">保存</button></td>
            </tr>
        </table>
    </form>	
<? } ?>

<? //////////////////////////////////////////修改密码/////////////////////////////////////////
if ($act=='cmpass'){?>
	<div class="local2"><b>修改我的密码</b></div>
	<form name="form1" method="post" action="?act=editok">
          <table  class="table_form" width="100%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="">
            <tr> 
              <td width="100">管理名称</td>
              <td width="" >
			<input name="text_name"  class="form-control input-md" type="text"  value="<? echo $_SESSION['adminName'];?>" readonly>
                   <input type="hidden" name="id" class="" value="<? echo $_SESSION['adminId'];?>"> 
			  </td>
            </tr>
            <tr> 
              <td>管理密码</td>
              <td ><input name="text_pass" type="text"  value="" class=":required :min_length;5  form-control input-md"></td>
            </tr>
            <tr> 
              <td>&nbsp;</td>
              <td ><button type="submit" class="btn btn-primary">保存</button></td>
            </tr>
        </table>

      </form>
<? } ?>
</div>
<?include('inc_foot.php');?>
</body>
</html>